home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
madtrb7.arc
/
HEXCALC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-12-01
|
4KB
|
165 lines
{$V-}
PROGRAM HEX;
{
Copyright (c) M-SQUARED Systems, Inc.- 1984
Permission granted for unlimited distribution and use by
individuals, so long as no charge is made for such use or
distribution.
W.B. Malthouse
5918 Veranda Dr.
Springfield, Va. 22152
}
type s4=string[4];
type pinteger=^integer;
VAR H:ARRAY[0..255] OF STRING[2];
var pp:pinteger;
var ii,jj,i,j,k:integer;
var a,b:string[255];
label 1,2,3;
VAR X,Y:REAL;
VAR N1,N2,N3,N4,N5:REAL;
PROCEDURE SETUP;
VAR T1,T2:CHAR;
VAR I,J,K:INTEGER;
BEGIN;
K:=0;
FOR I:=0 TO 15 DO BEGIN;
FOR J:=0 TO 15 DO BEGIN;
IF I>9 THEN T1:=CHR(I+55)
ELSE T1:=CHR(I+48);
IF J>9 THEN T2:=CHR(J+55)
ELSE T2:=CHR(J+48);
H[K]:=T1+T2;
K:=K+1;
END;
END;
END;
FUNCTION HEXWORD(j:integer): s4;
type bytes=array[1..2] of byte;
type bp=^bytes;
var q:bp;
VAR S:STRING[4];
begin;
q:=addr(j);
hexword:=h[q^[2]]+h[q^[1]];
end;
begin;
clrscr;
setup;
gotoxy(1,3);
writeln(' Hex Converter/Calculator Program');
writeln;
writeln(' Enter two numbers in HEX or in DECIMAL preceeded by "."');
writeln;
WRITELN('ENTER NUMBERS AT THE "N1:" AND "N2:" PROMPTS, USE "return" TO EXIT.');
repeat
1: ;
gotoxy(10,11);
write(' N1 N2 N1+N2 N1-N2 N2-N1');
gotoxy(1,20);
write('N1: ');
clreol;
gotoxy(1,21);
write('N2: ');
clreol;
gotoxy(5,20);
readln(a);
if a='' then
else begin;
if a[1]<>'.' then a:='$'+a
else BEGIN;
delete(a,1,1);
VAL(A,X,K);
IF K<>0 THEN BEGIN;
gotoxy(20,20);
write('Invalid Numeric Input');
sound(220);
delay(550);
nosound;
repeat; until(keypressed);
goto 1;
end;
IF X>32767.0 THEN X:=X*(-1.0)+32767;
I:=TRUNC(X);
GOTO 2;
END;
val(a,i,k);
if k<>0 then begin;
gotoxy(20,20);
write('Invalid Numeric Input');
sound(220);
delay(550);
nosound;
repeat; until(keypressed);
goto 1;
end;
2: gotoxy(5,21);
readln(b);
if b[1]<>'.' then b:='$'+b
else BEGIN;
delete(b,1,1);
VAL(B,Y,K);
IF K<>0 THEN BEGIN;
gotoxy(20,21);
write('Invalid Numeric Input');
sound(220);
delay(550);
nosound;
repeat; until(keypressed);
goto 1;
end;
IF Y>32767.0 THEN Y:=Y*(-1.0)+32767;
j:=TRUNC(Y);
GOTO 3;
END;
val(b,j,k);
if k<>0 then begin;
gotoxy(20,21);
write('Invalid Numeric Input');
sound(220);
delay(550);
nosound;
repeat; until(keypressed);
goto 1;
end;
3: N1:=INT(I);
N2:=INT(J);
N3:=N1+N2;
N4:=N1-N2;
N5:=N2-N1;
GOTOXY(1,13);
WRITE('HEX:');
GOTOXY(1,14);
WRITE('DEC:');
GOTOXY(5,14);
WRITE(N1:10:0,N2:10:0,N3:10:0,N4:10:0,N5:10:0);
GOTOXY(11,13);
write(hexword(i));
gotoxy(21,13);
write(hexword(j));
gotoxy(31,13);
ii:=i+j;
write(hexword(ii));
gotoxy(41,13);
jj:=i-j;
write(hexword(jj));
JJ:=J-I;
gotoxy(51,13);
write(hexword(jj));
GOTOXY(1,22);
repeat;
until(keypressed);
GOTOXY(1,13);
CLREOL;
GOTOXY(1,14);
CLREOL;
end;
until (a='');
gotoxy(1,22);
end.